package juc.day01;

/**
 * 两个线程，一个线程打印1-52，另一个打印字母A-Z，打印顺序为12A34B…5152Z。要求用线程间通信
 */
public class T01 {
    public static void main(String[] args) {
        ShareDataOne shareDataOne = new ShareDataOne();
        new Thread(()->{
            try {
                shareDataOne.printNumber();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(()->{
            try {
                shareDataOne.printWord();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}

class ShareDataOne{
    public synchronized void printNumber() throws InterruptedException {
        for(int i=1;i<=52;i++){
            System.out.println(i);
            if(i % 2 == 0){
                notify();
                wait();
            }
        }
    }

    public synchronized void printWord() throws InterruptedException{
            for(char i = 'A';i<='Z';i++){
                System.out.println(i);
                notify();
                wait();
            }
    }
}

